package com.pagoda.nerp.trade.common.wx.module;

import com.pagoda.nerp.trade.common.objectutil.PropertyConfigurer;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * 微信模板构建器
 * 主要用来构建模板data中的内容
 *
 * Created by Jungle on 2016/12/21.
 */
public class WxTemplateMsgBuilder {

    /**
     * 注册审核通知模板消息ID
     */
    public static String WX_TEMPLATE_REGISTER_NOTIFY = "EtXbw9DdsC7zoXyxwJPN1e3NA362ghZpj53K07My4Ks";

    /**
     * 信息发布通知模板
     */
    public static String WX_TEMPLATE_INFO_PUBLISH_NOTIFY = "Ht5KbOqbGlCca45lhXKyEpJIiAgClggtuUgN2JwxlnA";

    /**
     * 质检问题发布提醒
     */
    public static String WX_TEMPLATE_QUALITY_PUBLICSH_NOTIFY = "jiU3DoT0QcVZmckndcZqXWT4zdo0KGmvZHcct3Eg7hc";

    /**
     * 中标通知消息模板ID
     */
    public static String WX_TEMPLATE_BID_NOTIFY = "ekWUuwmGtyDdDy2kxjS2G-JiWJnRFhk7ao0CPEz1WHY";

    // 新采购提醒
    public static String WX_TEMPLATE_NEW_PURCHASE_NOTIFY;

    // 收到报价通知
    public static String WX_TEMPLATE_RECEIVE_OFFER_NOTIFY;

    // 新询价单通知
    public static String WX_TEMPLATE_NEW_INQUIRE_NOTIFY;

    // 质检申请发布通知
    public static String WX_TEMPLATE_APPLY_PURCHASE_PUBLISH_NOTIFY;

    // 质检需求反馈通知
    public static String WX_TEMPLATE_DEMAND_FEEDBACK_NOTIFY;

    // 报告生成通知
    public static String WX_TEMPLATE_REPORT_GENERATOR_NOTIFY;

    /**
     * 测试模板
     */
    public static String TEST_TEMPLATE_ID = "LvWpLMjjmLOaLzrGkta1gLDCW5esa7QTOnDPZSYdEwI";

    public static String CONSTAT_REMART = "如有疑问请致电4001811212！";

    static {
        WX_TEMPLATE_NEW_PURCHASE_NOTIFY = PropertyConfigurer.parseStr("wx.template.newPurchaseNotify");
        WX_TEMPLATE_RECEIVE_OFFER_NOTIFY = PropertyConfigurer.parseStr("wx.template.receiveOfferNotify");
        WX_TEMPLATE_NEW_INQUIRE_NOTIFY = PropertyConfigurer.parseStr("wx.template.newInquiryNotify");
        WX_TEMPLATE_APPLY_PURCHASE_PUBLISH_NOTIFY = PropertyConfigurer.parseStr("wx.template.applyPurchasePublishNotify");
        WX_TEMPLATE_DEMAND_FEEDBACK_NOTIFY = PropertyConfigurer.parseStr("wx.template.demandFeedbackNotify");
        WX_TEMPLATE_REPORT_GENERATOR_NOTIFY = PropertyConfigurer.parseStr("wx.template.reportGeneratorNotify");

        WX_TEMPLATE_REGISTER_NOTIFY = PropertyConfigurer.parseStr("wx.template.registerNotify");
        WX_TEMPLATE_INFO_PUBLISH_NOTIFY = PropertyConfigurer.parseStr("wx.template.infoPublishNotify");
        WX_TEMPLATE_QUALITY_PUBLICSH_NOTIFY = PropertyConfigurer.parseStr("wx.template.qualityPublishNotify");
        WX_TEMPLATE_BID_NOTIFY = PropertyConfigurer.parseStr("wx.template.bidNotify");
        CONSTAT_REMART = PropertyConfigurer.parseStr("wx.template.phone.remark");
    }

    /**
     * 构建注册审核通知模板消息
     * {{first.DATA}}
     * 用户名：{{keyword1.DATA}}
     * 手机号：{{keyword2.DATA}}
     * 时间：{{keyword3.DATA}}
     * {{remark.DATA}}
     * @param map
     * @return
     */
    public static Map<String,Object> buildNotifytTpl(Map<String,Object> map){
        Map returnResult = new HashMap();
        Object first = map.get("first");
        Object keyword1 = map.get("keyword1");
        Object keyword2 = map.get("keyword2");
        Object keyword3 = map.get("keyword3");
        Object keyword4 = map.get("keyword4");
        Object remark = map.get("remark");
        String color = "#173177";
        if(null != first && !"".equals(first.toString())){
            Map firstMap = new HashMap();
            firstMap.put("value",first.toString());
            firstMap.put("color",color);
            returnResult.put("first", firstMap);
        }
        if(null != keyword1 && !"".equals(keyword1.toString())){
            Map keyword1Map = new HashMap();
            keyword1Map.put("value", keyword1.toString());
            keyword1Map.put("color",color);
            returnResult.put("keyword1", keyword1Map);
        }
        if(null != keyword2 && !"".equals(keyword2.toString())){
            Map keyword2Map = new HashMap();
            keyword2Map.put("value", keyword2.toString());
            keyword2Map.put("color",color);
            returnResult.put("keyword2", keyword2Map);
        }
        if(null != keyword3 && !"".equals(keyword3.toString())){
            Map keyword3Map = new HashMap();
            keyword3Map.put("value", keyword3.toString());
            keyword3Map.put("color",color);
            returnResult.put("keyword3", keyword3Map);
        }
        if(null != keyword4 && !"".equals(keyword4.toString())){
            Map keyword4Map = new HashMap();
            keyword4Map.put("value", keyword4.toString());
            keyword4Map.put("color",color);
            returnResult.put("keyword4", keyword4Map);
        }
        if(null != remark && !"".equals(remark.toString())){
            Map remarkMap = new HashMap();
            remarkMap.put("value", remark.toString());
            remarkMap.put("color",color);
            returnResult.put("remark", remarkMap);
        }
        return returnResult;
    }


    /**
     * 构建通用模板消息参数
     *
     * 此构造函数对应模板ID ：LvWpLMjjmLOaLzrGkta1gLDCW5esa7QTOnDPZSYdEwI
     *
     * @param content 模板替换内容
     * @return JSON结构的字符串
     */
    public static Map buildTestTemplate(String content) {
        Map map = new HashMap();
        Map dataMap = new HashMap();
        dataMap.put("value", content);
        dataMap.put("color","#173177");
        map.put("remark", dataMap);
        return map;
    }

}
